<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>单位简历管理</title>
    <link rel="stylesheet" href="../../plugins/element-ui/theme-chalk/index.css"/>
    <script src="../../js/vue.js" charset="utf-8"></script>
    <script src="../../plugins/element-ui/index.js" charset="utf-8"></script>
    <!-- 引入axios -->
    <script src="../../plugins/axios.min.js"></script>

    <script src="../../js/candidates.js"></script>

    <script src="../../js/request.js"></script>

    <style name="table">
        .el-table .warning-row {
            background: oldlace;
        }

        .el-table .success-row {
            background: #f0f9eb;
        }
    </style>
</head>
<body>

<div id="container">
    <!--搜索表单    -->
    <el-form :inline="true" :model="resume" class="demo-form-inline">
        <el-form-item label="岗位名">
            <el-input v-model="resume.position" placeholder="岗位名"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
    </el-form>


    <!--table表格 -->
    <template>
        <el-table
                :data="tableData"
                style="width: 100%"
                :row-class-name="tableRowClassName"
                @selection-change="handleSelectionChange">
            <el-table-column
                    type="selection"
                    align="center"
                    width="55">
            </el-table-column>
            <el-table-column
                    type="index"
                    label="次序"
                    width="50">
            </el-table-column>
            <el-table-column
                    prop="position"
                    label="岗位"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="name"
                    label="姓名"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="graduation"
                    label="毕业院校"
                    align="center">
            </el-table-column>
            <el-table-column
                    prop="technologyStack"
                    label="技术栈"
                    align="center">
            </el-table-column>
            <el-table-column
                    align="center"
                    label="操作">
                <!--审核对话框表单-->
                <template slot-scope="scope">
                <el-row>
                <el-button type="primary"  @click="examine(scope.row)">审核</el-button>
                </el-row>
                    <el-dialog title="学生个人信息" :visible.sync="dialogFormVisible">
                        <el-form :model="student">
                            <el-form-item label="姓名" :label-width="formLabelWidth">
                                <el-input v-model="student.name" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="电话" :label-width="formLabelWidth">
                                <el-input v-model="student.phone" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="年龄" :label-width="formLabelWidth">
                                <el-input v-model="student.age" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="毕业院校" :label-width="formLabelWidth">
                                <el-input v-model="student.graduation" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="所学专业" :label-width="formLabelWidth">
                                <el-input v-model="student.major" autocomplete="off"></el-input>
                            </el-form-item>
                            <el-form-item label="常居地" :label-width="formLabelWidth">
                                <el-input v-model="student.address" autocomplete="off"></el-input>
                            </el-form-item>
                            </el-form-item>
                            <el-form-item label="自我评价" :label-width="formLabelWidth">
                                <el-input v-model="student.selfEvaluation" autocomplete="off"></el-input>
                            </el-form-item>
                        </el-form>
                        <div slot="footer" class="dialog-footer">
                            <el-button @click="dialogFormVisible = false">取 消</el-button>
                            <el-button @click="dialogFormVisible = false">拒绝</el-button>
                            <el-button type="primary" @click="accept">通过</el-button>
                        </div>
                    </el-dialog>
                </template>
            </el-table-column>
        </el-table>
    </template>

</div>

<script>
    new Vue({
        el:"#container",
        methods: {
            //使不同行颜色不同
            tableRowClassName({row, rowIndex}) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },

            //查询全部数据
            selectAll(){
                list(this.resume).then(res => {
                    if (String(res.code) === '1') {
                        this.tableData=res.data;
                    } else {
                        this.$message.error(res.msg || '查询失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },

            //点击查询后执行
            onSubmit() {
                queryResume(this.resume).then(res=> {
                    this.tableData=res.data;
                }).then(res => {
                    //判断响应数据是否为success
                    if(String(res.code) === "1"){
                        //提示消息
                        this.$message({
                            message: '查询成功！',
                            type: 'success'
                        })
                    }
                })
            },

            //审核
            examine(row){
                this.dialogFormVisible=true;
                this.resume.name=row.name;
                this.resume.position=row.position;
                this.resume.employerName=row.employerName;
                //要获取到该学生的个人信息
                getStudent(this.resume).then(res => {
                    if (String(res.code) === "1") {
                        this.student=res.data;
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                })
            },
            //通过简历
            accept(){
                accept({
                    //返回岗位名字便于修改对应简历状态
                    'position':this.resume.position,
                    'employerName':this.resume.employerName,
                    'name':this.resume.name,
                    'status': "已通过",
                }).then(res => {
                    if (String(res.code) === "1") {
                        this.$message.success('通过简历！')
                        this.dialogFormVisible = false;
                        this.selectAll();
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },

            //拒绝
            Delete(){
                deleteRecruit({
                    //返回名字和岗位便于修改对应简历状态
                    'name':this.resume.name,
                    'position':this.resume.position,
                    'employerName':this.resume.employerName,
                    'status': '被回拒',
                }).then(res => {
                    if (String(res.code) === "1") {
                        this.$message.success('回拒成功！')
                        this.dialogFormVisible = false;
                        this.selectAll();
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },

        },
        created() {
            this.resume.employerName=localStorage.getItem('user');
            this.selectAll();
        },
        data() {
            return {
                tableData: [],
                //复选框选中数据集合
                multipleSelection:[],

                //简历模型数据
                resume:{
                    name:"",
                    //应聘岗位
                    position:"",
                    //毕业院校
                    graduation:"",
                    //技术栈
                    technologyStack:"",

                    employerName:'',
                },
                //学生信息模型数据
                student:{
                    name:"",
                    phone:"",
                    age:"",
                    //毕业院校
                    graduation:"",
                    //所学专业
                    major:"",
                    //常居地
                    address:"",
                    //自我评价
                    selfEvaluation:"",
                },
                //默认对话框显示状态和宽度
                dialogFormVisible: false,
                formLabelWidth: '80px',

            }
        }
    })
</script>
</body>
</html>